package org.imis.action;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.hibernate.HibernateException;
import org.imis.domain.*;
import org.imis.service.NewsManage;

public class SaveAlter {
	private NewsManage newsManage;
    private String title;
    private String content;
    private String table;
    private String id;
    
  	public String getId() {
  		return id;
  	}
  	public void setId(String id) {
  		this.id = id;
  	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getTable() {
		return table;
	}
	public void setTable(String table) {
		this.table = table;
	}

	public String execute() throws NumberFormatException, HibernateException, ClassNotFoundException
	{
		 Date date=new Date();  
		 SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
		 String time=formatter.format(date);  
		 System.out.println(time);
		 if(table.equals("News"))
		 {
		News news=(News) newsManage.findOneList(table,Integer.parseInt(id));
		news.setTitle(title);
		news.setContent(content);
		news.setTime(time);
		newsManage.saveAlter(news);
		 }
		 else if(table.equals("Notice"))
		 {
			 Notice news=(Notice) newsManage.findOneList(table,Integer.parseInt(id));
				news.setTitle(title);
				news.setContent(content);
				news.setTime(time);
				newsManage.saveAlter(news);
			 
		 }
		 else if(table.equals("Forum"))
		 {
			 Forum news=(Forum) newsManage.findOneList(table,Integer.parseInt(id));
				news.setTitle(title);
				news.setContent(content);
				news.setTime(time);
				newsManage.saveAlter(news);
			 
		 }
		 else if(table.equals("Information"))
		 {
			 Information news=(Information) newsManage.findOneList(table,Integer.parseInt(id));
				news.setTitle(title);
				news.setContent(content);
				news.setTime(time);
				newsManage.saveAlter(news);
			 
		 }
		 else if(table.equals("PConsult"))
		 {
			 PConsult news=(PConsult) newsManage.findOneList(table,Integer.parseInt(id));
				news.setTitle(title);
				news.setContent(content);
				news.setTime(time);
				newsManage.saveAlter(news);
			 
		 }
		 else if(table.equals("RConsult"))
		 {
			 RConsult news=(RConsult) newsManage.findOneList(table,Integer.parseInt(id));
				news.setTitle(title);
				news.setContent(content);
				news.setTime(time);
				newsManage.saveAlter(news);
			 
		 }
		 else if(table.equals("StudentShip"))
		 {
			 StudentShip news=(StudentShip) newsManage.findOneList(table,Integer.parseInt(id));
				news.setTitle(title);
				news.setContent(content);
				news.setTime(time);
				newsManage.saveAlter(news);
			 
		 }
		 else if(table.equals("StuGroup"))
		 {
			 StuGroup news=(StuGroup) newsManage.findOneList(table,Integer.parseInt(id));
				news.setTitle(title);
				news.setContent(content);
				news.setTime(time);
				newsManage.saveAlter(news);
			 
		 }
		 else if(table.equals("StuHonor"))
		 {
			 StuHonor news=(StuHonor) newsManage.findOneList(table,Integer.parseInt(id));
				news.setTitle(title);
				news.setContent(content);
				news.setTime(time);
				newsManage.saveAlter(news);
			 
		 }
	    return "success";
	}
	public NewsManage getNewsManage() {
		return newsManage;
	}
	public void setNewsManage(NewsManage newsManage) {
		this.newsManage = newsManage;
	}



}
